﻿package core.ui
{
    import core.enum.*;
    import core.ui.controls.*;
    import core.ui.util.*;
    import flash.display.*;
    import flash.events.*;

    public class Toolbar extends Box
    {
        var maincolor:ColorPad;
        var secondcolor:ColorPad;
        var tools:Sprite;
        var at:ToolButton;

        public function Toolbar(param1:Tuyitu)
        {
            super(param1, "rm_tools", 65, 483);
            this.close.visible = false;
            this.tools = new Sprite();
            this.tools.addChild(new ToolButton(ToolType.Crop, new CropIcon(), 7, 22, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Move, new MoveIcon(), 34, 22, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Marquee, new MarqueeIcon(), 7, 49, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Lasso, new LassoIcon(), 34, 49, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Wand, new WandIcon(), 7, 76, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Type, new TypeIcon(), 34, 76, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            var _loc_2:* = new BoxSplit("small");
            _loc_2.x = 6;
            _loc_2.y = 103;
            addChild(_loc_2);
            this.tools.addChild(new ToolButton(ToolType.Pencil, new PencilIcon(), 7, 107, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Brush, new BrushIcon(), 34, 107, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Eraser, new EraserIcon(), 7, 134, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Clone, new CloneIcon(), 34, 161, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Gradient, new GradientIcon(), 7, 161, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Fill, new FillIcon(), 34, 134, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.ColorReplace, new ColorReplaceIcon(), 7, 188, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Drawing, new DrawingIcon(), 34, 188, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            var _loc_3:* = new BoxSplit("small");
            _loc_3.x = 6;
            _loc_3.y = 215;
            addChild(_loc_3);
            this.tools.addChild(new ToolButton(ToolType.Blur, new BlurIcon(), 7, 219, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Sharpen, new SharpenIcon(), 34, 219, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Smudge, new SmudgeIcon(), 7, 246, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Sponge, new SpongeIcon(), 34, 246, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Dodge, new DodgeIcon(), 7, 273, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Burn, new BurnIcon(), 34, 273, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.RedEyeReduction, new RedEyeIcon(), 7, 300, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.SpotHeal, new SpotHealIcon(), 34, 300, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Bloat, new BloatIcon(), 7, 327, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Pinch, new PinchIcon(), 34, 327, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            var _loc_4:* = new BoxSplit("small");
            _loc_4.x = 6;
            _loc_4.y = 354;
            addChild(_loc_4);
            this.tools.addChild(new ToolButton(ToolType.Picker, new PickerIcon(), 7, 358, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            this.tools.addChild(new ToolButton(ToolType.Type, new TypeIcon(), 34, 358, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide));
            var _loc_5:* = new ToolButton(ToolType.Hand, new HandIcon(), 7, 385, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide);
            _loc_5.addEventListener(MouseEvent.DOUBLE_CLICK, this.ToolDoubleClick, false, 0, true);
            _loc_5.mouseChildren = false;
            _loc_5.doubleClickEnabled = true;
            this.tools.addChild(_loc_5);
            var _loc_6:* = new ToolButton(ToolType.Zoom, new ZoomIcon(), 34, 385, this.ToolMouseDown, this.ToolMouseOver, param1.hover.Hide);
            _loc_6.addEventListener(MouseEvent.DOUBLE_CLICK, this.ToolDoubleClick, false, 0, true);
            _loc_6.mouseChildren = false;
            _loc_6.doubleClickEnabled = true;
            this.tools.addChild(_loc_6);
            addChild(this.tools);
            var _loc_7:* = new BoxSplit("small");
            _loc_7.x = 6;
            _loc_7.y = 412;
            addChild(_loc_7);
            var _loc_8:* = new Sprite();
            _loc_8.x = 6;
            _loc_8.y = 424;
            this.secondcolor = new ColorPad(4294967295);
            this.secondcolor.x = 20;
            this.secondcolor.y = 16;
            this.maincolor = new ColorPad(4278190080);
            this.maincolor.x = 2;
            this.maincolor.y = 0;
            this.maincolor.addEventListener(MouseEvent.MOUSE_UP, this.ColorMouseDown, false, 0, true);
            this.maincolor.addEventListener(MouseEvent.MOUSE_OVER, this.MainColorMouseOver, false, 0, true);
            this.maincolor.addEventListener(MouseEvent.MOUSE_OUT, param1.hover.Hide, false, 0, true);
            this.secondcolor.addEventListener(MouseEvent.MOUSE_UP, this.ColorMouseDown, false, 0, true);
            this.secondcolor.addEventListener(MouseEvent.MOUSE_OVER, this.SecondColorMouseOver, false, 0, true);
            this.secondcolor.addEventListener(MouseEvent.MOUSE_OUT, param1.hover.Hide, false, 0, true);
            _loc_8.addChild(this.secondcolor);
            _loc_8.addChild(this.maincolor);
            var _loc_9:* = new Sprite();
            _loc_9.addChild(new Bitmap(new SwitchPad()));
            _loc_9.addEventListener(MouseEvent.MOUSE_DOWN, this.SwitchMouseDown, false, 0, true);
            _loc_9.addEventListener(MouseEvent.MOUSE_OVER, this.SwitchMouseOver, false, 0, true);
            _loc_9.addEventListener(MouseEvent.MOUSE_OUT, param1.hover.Hide, false, 0, true);
            _loc_9.x = 36;
            _loc_9.y = 2;
            _loc_8.addChild(_loc_9);
            var _loc_10:* = new Sprite();
            _loc_10.addChild(new Bitmap(new ResetPad()));
            _loc_10.addEventListener(MouseEvent.MOUSE_DOWN, this.ResetMouseDown, false, 0, true);
            _loc_10.addEventListener(MouseEvent.MOUSE_OVER, this.ResetMouseOver, false, 0, true);
            _loc_10.addEventListener(MouseEvent.MOUSE_OUT, param1.hover.Hide, false, 0, true);
            _loc_10.x = 4;
            _loc_10.y = 33;
            _loc_8.addChild(_loc_10);
            addChild(_loc_8);
            return;
        }// end function

        public function SelectTool(MOUSE_OVER:ToolType) : void
        {
            var _loc_2:ToolButton = null;
            var _loc_3:int = 0;
            while (_loc_3 < this.tools.numChildren)
            {
                
                _loc_2 = this.tools.getChildAt(_loc_3) as ToolButton;
                if (_loc_2.type == MOUSE_OVER)
                {
                    if (this.at != null)
                    {
                        this.at.Mark(false);
                    }
                    ed.SetTool(_loc_2.type);
                    _loc_2.Mark(true);
                    this.at = _loc_2;
                    break;
                }
                _loc_3++;
            }
            return;
        }// end function

        private function SwitchMouseOver(event:MouseEvent) : void
        {
            ed.hover.Set(U.RM("rm_switch_colors") + " (X)");
            return;
        }// end function

        private function SwitchMouseDown(event:MouseEvent) : void
        {
            this.SwitchColors();
            return;
        }// end function

        private function ResetMouseOver(event:MouseEvent) : void
        {
            ed.hover.Set(U.RM("rm_default_colors") + " (D)");
            return;
        }// end function

        private function ResetMouseDown(event:MouseEvent) : void
        {
            this.ResetColors();
            return;
        }// end function

        public function SwitchColors() : void
        {
            var _loc_1:* = this.maincolor.value;
            var _loc_2:* = this.secondcolor.value;
            this.maincolor.Set(_loc_2);
            this.secondcolor.Set(_loc_1);
            return;
        }// end function

        public function ResetColors() : void
        {
            this.maincolor.Set(4278190080);
            this.secondcolor.Set(4294967295);
            return;
        }// end function

        public function ToolMouseDown(event:MouseEvent) : void
        {
            if (this.at != null)
            {
                this.at.Mark(false);
            }
            this.at = event.currentTarget as ToolButton;
            this.at.Mark(true);
            ed.SetTool(this.at.type);
            return;
        }// end function

        public function ToolMouseOver(event:MouseEvent) : void
        {
            switch((event.currentTarget as ToolButton).type)
            {
                case ToolType.Marquee:
                {
                    ed.hover.Set(U.RM("rm_marquee_tool") + " (M)");
                    break;
                }
                case ToolType.Move:
                {
                    ed.hover.Set(U.RM("rm_move_tool") + " (V)");
                    break;
                }
                case ToolType.Wand:
                {
                    ed.hover.Set(U.RM("rm_wand_tool") + " (W)");
                    break;
                }
                case ToolType.Lasso:
                {
                    ed.hover.Set(U.RM("rm_lasso_tool") + " (L)");
                    break;
                }
                case ToolType.Crop:
                {
                    ed.hover.Set(U.RM("rm_crop_tool") + " (C)");
                    break;
                }
                case ToolType.Brush:
                {
                    ed.hover.Set(U.RM("rm_brush_tool") + " (B)");
                    break;
                }
                case ToolType.Pencil:
                {
                    ed.hover.Set(U.RM("rm_pencil_tool"));
                    break;
                }
                case ToolType.Gradient:
                {
                    ed.hover.Set(U.RM("rm_gradient_tool"));
                    break;
                }
                case ToolType.ColorReplace:
                {
                    ed.hover.Set(U.RM("rm_color_replace_tool"));
                    break;
                }
                case ToolType.Fill:
                {
                    ed.hover.Set(U.RM("rm_fill_tool") + " (G)");
                    break;
                }
                case ToolType.Clone:
                {
                    ed.hover.Set(U.RM("rm_clone_tool") + " (S)");
                    break;
                }
                case ToolType.Type:
                {
                    ed.hover.Set(U.RM("rm_type_tool") + " (T)");
                    break;
                }
                case ToolType.Drawing:
                {
                    ed.hover.Set(U.RM("rm_drawing_tool"));
                    break;
                }
                case ToolType.Blur:
                {
                    ed.hover.Set(U.RM("rm_blur_tool") + " (R)");
                    break;
                }
                case ToolType.Sharpen:
                {
                    ed.hover.Set(U.RM("rm_sharpen_tool") + " (Y)");
                    break;
                }
                case ToolType.Smudge:
                {
                    ed.hover.Set(U.RM("rm_smudge_tool") + " (U)");
                    break;
                }
                case ToolType.Sponge:
                {
                    ed.hover.Set(U.RM("rm_sponge_tool") + " (P)");
                    break;
                }
                case ToolType.Dodge:
                {
                    ed.hover.Set(U.RM("rm_dodge_tool") + " (O)");
                    break;
                }
                case ToolType.Burn:
                {
                    ed.hover.Set(U.RM("rm_burn_tool") + " (N)");
                    break;
                }
                case ToolType.SpotHeal:
                {
                    ed.hover.Set(U.RM("rm_spot_heal_tool"));
                    break;
                }
                case ToolType.RedEyeReduction:
                {
                    ed.hover.Set(U.RM("rm_red_eye_tool"));
                    break;
                }
                case ToolType.Bloat:
                {
                    ed.hover.Set(U.RM("rm_bloat_tool") + " (A)");
                    break;
                }
                case ToolType.Pinch:
                {
                    ed.hover.Set(U.RM("rm_pinch_tool") + " (K)");
                    break;
                }
                case ToolType.Eraser:
                {
                    ed.hover.Set(U.RM("rm_eraser_tool") + " (E)");
                    break;
                }
                case ToolType.Picker:
                {
                    ed.hover.Set(U.RM("rm_color_picker_tool") + " (I)");
                    break;
                }
                case ToolType.Hand:
                {
                    ed.hover.Set(U.RM("rm_hand_tool") + " (H)");
                    break;
                }
                case ToolType.Zoom:
                {
                    ed.hover.Set(U.RM("rm_zoom_tool") + " (Z)");
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function ToolDoubleClick(event:MouseEvent) : void
        {
            this.at = event.currentTarget as ToolButton;
            if (this.at.type == ToolType.Zoom)
            {
                ed.cm.ZoomActualPixels();
            }
            else if (this.at.type == ToolType.Hand)
            {
                ed.cm.ZoomShowAll();
            }
            return;
        }// end function

        public function GetColor(ResetMouseOver:int = 1, ResetMouseOver:Boolean = false) : uint
        {
            if (ResetMouseOver == 1)
            {
                return ResetMouseOver ? (4289003388) : (this.maincolor.value);
            }
            return this.secondcolor.value;
        }// end function

        public function SetColor(MOUSE_OVER:int, MOUSE_OVER:uint) : void
        {
            if (MOUSE_OVER == 1)
            {
                this.maincolor.Set(MOUSE_OVER);
            }
            else
            {
                this.secondcolor.Set(MOUSE_OVER);
            }
            return;
        }// end function

        public function ColorMouseDown(event:MouseEvent) : void
        {
            new ColorPicker(this.ed, event.target as ColorPad);
            return;
        }// end function

        private function MainColorMouseOver(event:MouseEvent) : void
        {
            ed.hover.Set("rm_set_foreground_color");
            return;
        }// end function

        private function SecondColorMouseOver(event:MouseEvent) : void
        {
            ed.hover.Set("rm_set_background_color");
            return;
        }// end function

    }
}
